package book.java8.char11;

/**
 * @author MI
 * @version 1.0
 * @date 2020/12/19 21:30
 */
public class Discount {
    public enum Code {
        NODE(0), SILVER(5), GOLD(10), PLATINUM(15),
        DIAMOND(20);
        private final int percentage;

        Code(int percentage) {
            this.percentage = percentage;
        }
    }

    public static String applyDiscount(Quote quote) {
        return quote.getShopName() + " price is " +
                Discount.apply(quote.getPrice(), quote.getDiscountCode());

    }

    private static double apply(double price, Code code) {
        delay();
        return price * (100 - code.percentage) / 100;
    }

    public static void delay() {
        try {
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
